﻿using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ResilienceCompute.Tool
{
    public class ExcelHelper
    {
        public static void ExportToExcel(List<double> data, string filePath, string sheetName = "Data")
        {
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            using (ExcelPackage excelPackage = new ExcelPackage(new FileInfo(filePath)))
            {
                ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add(sheetName);
                worksheet.Cells[1, 1].Value = "数值列表";
                for (int i = 0; i < data.Count; i++)
                {
                    worksheet.Cells[i + 2, 1].Value = data[i];
                }
                worksheet.Column(1).AutoFit();
                excelPackage.Save();
            }
        }
    }
}